package com.guofen.controller.shlj;

import com.guofen.pojo.ShljDeodorizationtowerWaterChange2;
import com.guofen.pojo.ShljDeodorizationtowerWaterChange3;
import com.guofen.service.shlj.DeodorizationtowerWaterChange3Service;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/shlj/deodorizationtowerWaterChange3")
@Controller
@Api(tags = "DeodorizationtowerWaterChange3Controller", description = "除臭塔换水记录")
public class DeodorizationtowerWaterChange3Controller {

    @Autowired
    private DeodorizationtowerWaterChange3Service service;

    @ApiOperation("开始放水")
    @RequestMapping(value = "/beginReducingWater",method = RequestMethod.POST)
    @ResponseBody
    public Result beginFlowing(@ApiParam(name="water_reduce_time",value="放水时间",required=true) @RequestParam String water_reduce_time,
                               @ApiParam(name="recording_person",value="记录人",required=true) @RequestParam String recording_person){
        if (service.beginReducingWater(water_reduce_time, recording_person))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("开始加水")
    @RequestMapping(value = "/beginAddingWater",method = RequestMethod.POST)
    @ResponseBody
    public Result beginAddingWater(@ApiParam(name="water_add_time",value="加水时间",required=true) @RequestParam String water_add_time,
                                   @ApiParam(name="water_addition",value="加水量",required=true) @RequestParam String water_addition,
                                   @ApiParam(name="deodorantstr",value="添加除臭剂(kg)",required=true) @RequestParam String deodorantstr,
                                   @ApiParam(name="freshenerstr",value="添加清新剂(kg)",required=true) @RequestParam String freshenerstr){
        Double water_add = Double.parseDouble(water_addition);
        Double deodorant = Double.parseDouble(deodorantstr);
        Double freshener = Double.parseDouble(freshenerstr);
            if (service.beginAddingWater(water_add_time, water_add, deodorant, freshener))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("开始清理填料")
    @RequestMapping(value = "/beginCleaningStuffing",method = RequestMethod.POST)
    @ResponseBody
    public Result beginCleaningStuffing(@ApiParam(name="clean_filler_time",value="清理填料时间",required=true) @RequestParam String clean_filler_time,
                                        @ApiParam(name="filler_end_time",value="填料结束时间",required=true) @RequestParam String filler_end_time,
                                        @ApiParam(name="clean_nozzle_numberstr",value="清理喷头个数",required=true) @RequestParam String clean_nozzle_numberstr){
        Integer clean_nozzle_number = Integer.parseInt(clean_nozzle_numberstr);
        if (service.beginCleaningStuffing(clean_filler_time, filler_end_time, clean_nozzle_number))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("查询记录")
    @RequestMapping(value = "/findForm",method = RequestMethod.GET)
    @ResponseBody
    public Result findForm(){
        if (service.findForm() != null)
            return ResultGenerator.genSuccessResult(service.findForm());
        else
            return ResultGenerator.genFailResult("暂无记录");
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(service.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="water_reduce_time",value="放水时间",required=true) @RequestParam String water_reduce_time,
                         @ApiParam(name="recording_person",value="记录人",required=true) @RequestParam String recording_person,
                         @ApiParam(name="water_add_time",value="加水时间",required=true) @RequestParam String water_add_time,
                         @ApiParam(name="water_addition",value="加水量",required=true) @RequestParam Double water_addition,
                         @ApiParam(name="deodorant",value="添加除臭剂(kg)",required=true) @RequestParam Double deodorant,
                         @ApiParam(name="freshener",value="添加清新剂(kg)",required=true) @RequestParam Double freshener,
                         @ApiParam(name="clean_filler_time",value="清理填料时间",required=true) @RequestParam String clean_filler_time,
                         @ApiParam(name="filler_end_time",value="填料结束时间",required=true) @RequestParam String filler_end_time,
                         @ApiParam(name="clean_nozzle_number",value="清理喷头个数",required=true) @RequestParam Integer clean_nozzle_number,
                         @ApiParam(name="remarks",value="备注",required=false) @RequestParam String remarks) {
        ShljDeodorizationtowerWaterChange3 record = new ShljDeodorizationtowerWaterChange3();
        record.setId(id);
        record.setWaterReduceTime(water_reduce_time);
        record.setRecordingPerson(recording_person);
        record.setWaterAddTime(water_add_time);
        record.setWaterAddition(water_addition);
        record.setDeodorant(deodorant);
        record.setFreshener(freshener);
        record.setCleanFillerTime(clean_filler_time);
        record.setFillerEndTime(filler_end_time);
        record.setCleanNozzleNumber(clean_nozzle_number);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(service.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(service.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(service.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
